{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Listening...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:snowboy:Keyword 1 detected at time: 2019-04-27 03:51:24\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "key word detected\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:snowboy:Keyword 1 detected at time: 2019-04-27 03:51:28\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "key word detected\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:snowboy:Keyword 1 detected at time: 2019-04-27 03:51:31\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "key word detected\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:snowboy:Keyword 1 detected at time: 2019-04-27 03:51:35\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "key word detected\n",
      "Interrupted\n"
     ]
    }
   ],
   "source": [
    "import snowboydecoder\n",
    "import sys\n",
    "import signal\n",
    "import os\n",
    "\n",
    "def call_back():\n",
    "    os.system(\"aplay resources/ding.wav\")\n",
    "    print(\"key word detected\")\n",
    "\n",
    "model = './resources/小白.pmdl'\n",
    "\n",
    "detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)\n",
    "\n",
    "print('Listening...')\n",
    "try:\n",
    "    # main loop\n",
    "    detector.start(detected_callback=call_back,sleep_time=0.03)\n",
    "except KeyboardInterrupt:\n",
    "        print('Interrupted')    \n",
    "finally:\n",
    "    detector.terminate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
